package demo;


import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author : feixiang.li
 * @since : 2025-06-05 10:38
 */
public class Test8 {

    public List<String> generateDateRangeList(String queryBeginDay, String queryEndDay) {
        if (queryBeginDay == null || queryEndDay == null) {
            throw new IllegalArgumentException("Both begin date and end date must be provided");
        }
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate startDate = LocalDate.parse(queryBeginDay, formatter);
        LocalDate endDate = LocalDate.parse(queryEndDay, formatter);

        if (startDate.isAfter(endDate)) {
            throw new IllegalArgumentException("Begin date cannot be after end date");
        }
        List<String> dateList = new ArrayList<>();
        LocalDate currentDate = startDate;

        while (!currentDate.isAfter(endDate)) {
            dateList.add(currentDate.format(formatter));
            currentDate = currentDate.plusDays(1);
        }
        return dateList;
    }

    public static void main(String[] args) {
        String startDate = "2025/10";
        DateTime parse = DateUtil.parse(startDate,"yyyy/M");
        System.out.println(parse);
        String dateStr = "2023/5";

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/M");
        try {
            Date date = sdf.parse(dateStr);
            System.out.println("解析后的日期: " + date);

            // 如果需要重新格式化为其他形式
            SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy年MM月");
            System.out.println("格式化输出: " + outputFormat.format(date));
        } catch (ParseException e) {
            System.err.println("日期解析错误: " + e.getMessage());
        }
    }
}
